﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using TS.DataAccess;
using TS.Entities;

namespace TS.Bussiness
{
   public class GroupPermissionBussiness
    {
        public Collection<PermissionGroup> ReadGroupPermissionPaged(int pageSize, int pageIndex, string strFilter, string strOrderBy,int groupId, out int totalRecord)
        {
            totalRecord = 0;
            var dataAccess = new PermissionGroupDataAccess();
            try
            {
                if (pageIndex >= 0 && pageSize > 0)
                {
                    var result = dataAccess.ReadPermissionGroupPaged(pageSize, pageIndex, strFilter, strOrderBy,groupId, out totalRecord);
                    if (result != null)
                    {
                        return result;
                    }
                    return null;
                }
                return null;
            }
            catch (SqlException exception)
            {
                Console.WriteLine(exception.ToString());
            }
            return null;
        }

        public int UpdatePermissionGroup(int groupId, int roleId, int check)
        {
            if (groupId <= 0 || roleId <=0 ) return -1;
            var dao = new PermissionGroupDataAccess();
            try
            {
                return dao.UpdatePermissionGroup(groupId, roleId, check);
            }
            catch (SqlException exception)
            {
                Console.WriteLine(exception.ToString());
            }
            return -1;
        }

    }
}
